package com.minminaya.source;

public class Algorithm_1 {

    public static boolean find(int[][] matrix, int number) {
        //判断输入条件
        if (matrix == null && matrix.length < 1 || matrix[0].length < 1) {
            return false;
        }

        int rows = matrix.length;//数组元素个数，为行数
        int cols = matrix[1].length;//数组第一个元素中韩的个数，为列数

        int row = 0;
        int col = cols - 1;

        while (row >= 0 && row < rows && col >= 0 && col <cols) {
            if (matrix[row][col] == number) {
                return true;
            } else if (matrix[row][col] > number) {
                col--;//如果找到的数比要找的数大，那么说明要找的数在当前数的左边，去掉这一列
            } else {
                row++;
            }
        }
        return false;
    }

    public static void main(String[] args) {


        System.out.println("Hello World!");
        int[][] intArrays = new int[][]{
                {1, 2, 3, 4, 5},
                {2, 3, 4, 5, 6},
                {3, 4, 5, 6, 7},
                {4, 5, 6, 7, 8}
        };

        boolean tmp = Algorithm_1.find(intArrays,9);
        System.out.print(tmp);
    }
}
